<?php

namespace App\Models\Diary;

use App\Libs\Base\Constant;

class Topic extends \App\Libs\Base\BaseModel
{
    protected $numPerPage = 10;
    public $period;
    protected $__TABLE__ = 't_paile_topic';

    /**
     *    跳过检测了
     */
    public function beforeValidation()
    {
        self::skipValidation(['ishot'], $this);
    }

    public function getNewlestPeriodNum()
    {
        $newPeriod = $this::find([
            'conditions' => 'isshow = ?1 ',
            'order' => 'period desc',
            'bind' => array(1 => true)
        ]);

        if (!empty($newPeriod) && isset($newPeriod->period)) {
            return $newPeriod->period;
        } else {
            return false;
        }
    }
//	//根据活动的ID，获取此活动的详细内容；
    public function getTopicDetail($topicPeriod)
    {

        $singleActivityData = $this::find([
            'conditions' => 'period=?1',
            'bind' => [1 => $topicPeriod]
        ]);
        
        return $singleActivityData;
    }
//
//	//通过简单的分页来获得活动
//	public function getLastTopic($page=1,$getNum=10)
//	{
//		if(!is_numeric($page) || $page < 1) {
//			//TODO:调用constant类进行预先定义的错误提示
//			$page = 1;
//		}
//		$needNum = isset($getNum)&&is_numeric($getNum) ? $getNum : $this->numPerPage;
//		$start = ($page-1)*$this->pageNum;
//		//期数暂时无法显示；可以选用Id即可；
//		$lastPerData = $this::findAll(
//			array(
//				"columns" => 'period,topic_title,topic_logo,topic_sum_comment',
//				"order" => 'ctime',
//				"offset" => $start,
//				"limit" => $needNum
//			)
//		);
//		return $lastPerData;
//	}

}